<?php

class Student_Model_DbTable_Grade extends Zend_Db_Table_Abstract {

	protected $_name = 'grades';


        public function getGrade($id)
        {
            $id = (int)$id;
            $row = $this->fetchRow('id = ' . $id);
            if (!$row)
                {
                    throw new Exception("Count not find row $id");
                }
            return $row->toArray();

        }
        public function getSingleUserGrades($assess_id)
        {
            $assess_id = (int)$assess_id;
            $row = $this->fetchAll('id_of_assessment = ' . $assess_id);

            if (!$row)
                {
                    throw new Exception("Count not find row $assess_id");
                }
            return $row;
        }

        

        
	public function addGrade($id_of_assessment, $grade, $grade_in_percent, $max_grade_in_percent)
        {

		$data = array (
		 'id_of_assessment' => $id_of_assessment,
                 'grade' => $grade,
                 'grade_in_percent' =>$grade_in_percent,
                 'max_grade_in_percent' => $max_grade_in_percent,
                 
		);
		$this->insert($data);
	}


        public function editGrade($id,$grade, $grade_in_percent, $max_grade_in_percent)
        {
            $data = array (

		 'id' => $id,
                 'grade' => $grade,
                 'grade_in_percent' =>$grade_in_percent,
                 'max_grade_in_percent' => $max_grade_in_percent,
		);

            $this->update($data, 'id = '. (int)$id);
        }


        public function deleteGrade($id)
        {
            $this->delete('id =' . (int)$id);
        }

}